

jQuery(function ($) {
    var onoff = false;
    var url = window.location.pathname.split('/')[3];
    if (url) {
        var requestGoodsList = function requestGoodsList(page, url) {
            var params = {
                'HofArtist': {
                    'url': url,
                    'Artist': {
                        'id@': 'HofArtist/id'
                    }
                },
                '[]': {
                    'page': page,
                    'count': 21,
                    'query': 2,
                    'Goods': {
                        'artist_id@': 'HofArtist/id',
                        'hof_flag': 1,
                        'GoodsImgs': {
                            'goods_id@': '[]/Goods/id',
                            'main_flag': 1
                        }
                    }
                },
                'total@': '[]/total'
            };
            send_ajax('post', '/get', params, function callback(res) {
                if (res.code == 200 && res['[]']) {
                    var html = "";
                    var data = res['[]'];
                    for (var k = 0; k < data.length; k++) {
                        if (data[k].Goods.preview_flag) {
                            data[k].Goods.evaluate_price = data[k].Goods.evaluate_price.split(',');
                            if (data[k].Goods.evaluate_price.length > 1 && data[k].Goods.evaluate_price[1] == 0) {
                                data[k].Goods.evaluate_price = '预估价:' + "￥" + data[k].Goods.evaluate_price[0] + '以上';
                            } else if (data[k].Goods.evaluate_price.length > 1 && data[k].Goods.evaluate_price[1] != 0) {
                                data[k].Goods.evaluate_price = '预估价:' + "￥" + data[k].Goods.evaluate_price.join('-');
                            };
                            if (data[k].Goods.evaluate_price.length == 1) {
                                if (Number(data[k].Goods.evaluate_price[0])) {
                                    data[k].Goods.evaluate_price = '预估价:' + "￥" + data[k].Goods.evaluate_price;
                                } else {
                                    data[k].Goods.evaluate_price = '预估价:' + data[k].Goods.evaluate_price;
                                }
                            }
                        }
                    }

                    for (var i = 0; i < data.length; i++) {
                        if (data[i].Goods) {
                            html += ' <li>\n                                    <div class="hof_goodsinfo">\n                                        <a href="/goods-' + data[i].Goods.id + '.html" target="_blank" taget="_blank"><img src="' + isImgHttp(data[i].Goods.GoodsImgs.thumb) + '" alt=""></a>\n                                        <i class="g_status goods_status1 ' + (data[i].Goods.stock < 1 ? 'open' : 'hide') + '"></i><!--\u5DF2\u552E -->\n                                        <i class="g_status goods_status2 ' + (data[i].Goods.preview_flag == 1 ? 'open' : 'hide') + '"></i><!--\u6B23\u8D4F -->\n                                        <i class="g_status goods_status3 ' + (data[i].Goods.gift_flag == true ? 'open' : 'hide') + '"></i><!--\u8D60\u54C1 -->\n                                        <i class="g_status goods_status4 ' + (data[i].Goods.onsale_flag == false ? 'open' : 'hide') + ('"></i><!--\u4E0B\u67B6 -->\n                                    </div>\n                                    <div class="pic_msg">\n                                        <p><a href="/goods-' + data[i].Goods.id + '.html" taget="_blank">' + data[i].Goods.name + '</a></p>\n                                        <div class="pic_bottom">\n                                            <span class="price">' + (data[i].Goods.preview_flag ? data[i].Goods.evaluate_price : '￥' + data[i].Goods.goods_price) + '</span>\n                                            <a href="/goods-' + data[i].Goods.id + '.html" taget="_blank">\u70B9\u51FB\u67E5\u770B</a>\n                                        </div>\n                                    </div>\n                                </li>');
                        }
                    };
                    $('.goods_list').html(html);
                }
            });
        };

        // var url = $('#pagination_jijin').attr('data-url');
        var total = $('#num').html();
        //分页按钮
        Page({
			num:(Math.ceil(total / 12)),					//页码数
			startnum:1,				//指定页码
			elem:$('#pagination_jijin'),		//指定的元素
			callback:function(page){	//回调函数
                if (page != 1) {
                    onoff = true;
                }
                if (onoff) {
                    requestGoodsList(page);
                    $('.goods_list').html('');
                    $('html,body').animate({scrollTop:$('.fm_content ').offset().top-80}, 500);
                }
			}
		});
    }
});